import axios from 'axios'

const api = axios.create({
  baseURL: process.env.VUE_APP_API_URL || 'http://localhost:3000',
  timeout: 5000,
  headers: {
    'Content-Type': 'application/json'
  }
})

// 添加响应拦截器
api.interceptors.response.use(
  response => response.data,
  error => {
    console.error('API请求失败:', error)
    throw error
  }
)

export const getVariableSuggestions = async (text) => {
  try {
    return await api.post('/api/translate', {
      text,
      type: 'variable'
    })
  } catch (error) {
    throw new Error('获取变量名建议失败')
  }
} 